package com.yk.framework.gui.ctrl;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JToolBar;

/**
 * @author lifetime
 * 
 */
@SuppressWarnings("serial")
public class YKToolBar extends JToolBar {
	protected int comCount;
	private Color bc = new Color(181, 198, 216);

	public Component add(Component c) {
		Component com = super.add(c);
		comCount++;
		recumputerPreSize();
		return com;
	}

	protected void recumputerPreSize() {
		this.setPreferredSize(new Dimension(80 * comCount, this.getPreferredSize().height));
	}

	public void remove(Component c) {
		super.remove(c);
		comCount--;
		recumputerPreSize();
	}

	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D) g.create();
		GradientPaint p = new GradientPaint(0, 0, Color.white, 0, getHeight(), bc);
		g2.setPaint(p);
		g2.fillRect(0, 0, getWidth(), getHeight());
		g2.dispose();
	}
}
